<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title></title>
  </head>
  <body>
    <div id="app">
      <btn-a></btn-a>
    </div>

    <script src="./vue.js"></script>
    <script>
      const vm = new Vue({
        el: "#app",
        data: {},
        methods: {},
        components: {
          
          "btn-a": {
            template: `<div>子传过来的数据：{{msg}}<btn-b @transfer=fn($event)></btn-b></div>`,
            data() {
              return {
                msg:""
              };
            },
            methods:{
              fn(e){
                this.msg=e
              }
            },
            components: {
              "btn-b": {
                template: `<div><button @click=fn()>点击传值</button></div>`,
                data() {
                  return {
                    msg: "子组件数据",
                  };
                },
                methods: {
                  fn() {
                    this.$emit("transfer", this.msg);
                  },
                },
              },
            },
          },
        },
      });
    </script>
  </body>
</html>
